import { createRouter, createWebHistory } from 'vue-router'
import Home from "@/views/Home.vue";
import Login from "@/views/Login.vue";
import SignUp from "@/views/SignUp.vue";
import Main from "@/components/Main/Main.vue";
import Map from "@/components/Main/Map.vue";
import Collect from "@/components/Collect.vue";
import Personal from "@/components/Personal.vue";
import RouteProfile from "@/components/RouteProfile.vue";
import Details from "@/components/details.vue";
import Admin from "@/components/Admin/Admin.vue";
import AdminHome from "@/views/AdminHome.vue";
import ManageUser from "@/components/Admin/ManageUser.vue";
import ManageFlight from "@/components/Admin/ManageFlight.vue";
const routes = [
  {
    path:'/',
    name:'home',
    component:Home,
    redirect: '/main',
    children: [
        {path:'/main',component:Main},
      {path:'/collect',component:Collect},
      {path: '/personal',component:Personal},
      {path:'/routeProfile',component:RouteProfile},
    ]
  },
  {
    path:'/details',
    component:Details
  },
  {
    path:'/login',
    name:'login',
    component:Login,
  },
  {
    path:'/map',
    name:'map',
    component:Map,
  },
  {
    path:'/signUp',
    name:'signup',
    component:SignUp,
  },
    {
        path:'/adminHome',
        name:'adminHome',
        component:AdminHome,
        redirect: '/admin',
        children: [
            {path:'/admin',component:Admin},
            {path:'/manageUser',component:ManageUser},
            {path: '/manageFlight',component:ManageFlight}
        ]
    },
  ]

/*//挂载路由导航守卫
//to是我们跳转的路径，from是来自的路径，next为放行函数
router.beforeEach((to,from,next)=>{
  //如果用户访问登录页，直接放行
  if(to.path ==="/login") return next();
  //从sessionStorage中获取到保存的token值
  const tokenStr = window.sessionStorage.getItem("token");
  //没有token，强制跳转到登录页面
  if(!tokenStr) return next("/login");
  next();//有token，直接放行
})*/
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
